package com.cloudlinkscm.base.filecenter.code;

import com.cloudlinkscm.loms.framework.core.pojo.ErrorCode;
import com.cloudlinkscm.loms.framework.core.pojo.ErrorMessage;
import com.cloudlinkscm.loms.framework.core.pojo.Language;

import java.util.HashMap;

/**
 * @author : syq
 * @date : 2017/7/22
 */
public enum FileCenterErrorCode implements ErrorCode {

    FILE_EMPTY("151"),
    FILE_SAVE_EXCEPTION("152"),
    NOT_AUTHORIZED_EXCEPTION("153"),
    FILE_REMOVE_EXCEPTION("154"),
    FILE_STREAM_NOT_EXIST_EXCEPTION("155"),
    FILE_STREAM_EXPIRED_EXCEPTION("156"),
    FILE_NOT_EXIST_EXCEPTION("157"),
    INVALID_REQUEST_EXCEPTION("158"),
    AUTHENTICATE_FAILURE_EXCEPTION("159"),
    AUTHORIZED_CODE_EXPIRED_EXCEPTION("160"),

    ;

    private String code;
    FileCenterErrorCode(String code) {
        this.code = code;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return errorMessage.getErrorMessage(this);
    }

    @Override
    public String getInternationalMessage(Language language) {
        return errorMessage.getInternationalErrorMessage(this, language);
    }

    @Override
    public String getInternationalMessage(Language language, Object... args){
        return errorMessage.getInternationalErrorMessage(this, language, args);
    }

    private static HashMap<ErrorCode, String> zh = new HashMap<>();
    private static HashMap<ErrorCode, String> en = new HashMap<>();
    static {
       zh.put(FILE_EMPTY,"文件为空！");
       zh.put(FILE_SAVE_EXCEPTION,"文件存储失败");
       zh.put(NOT_AUTHORIZED_EXCEPTION,"系统\"%s\"未授权");
       zh.put(FILE_REMOVE_EXCEPTION,"文件删除失败");
       zh.put(FILE_STREAM_NOT_EXIST_EXCEPTION,"文件流不存在");
       zh.put(FILE_STREAM_EXPIRED_EXCEPTION,"文件流已过期");
       zh.put(FILE_NOT_EXIST_EXCEPTION,"文件不存在");
       zh.put(INVALID_REQUEST_EXCEPTION,"无效请求：%s");
       zh.put(AUTHENTICATE_FAILURE_EXCEPTION,"身份验证失败：%s");
       zh.put(AUTHORIZED_CODE_EXPIRED_EXCEPTION,"系统授权码\"%s\"已过期");
    }

    static {
        en.put(FILE_EMPTY,"file is empty!");
        en.put(FILE_SAVE_EXCEPTION,"fail to save file");
        en.put(NOT_AUTHORIZED_EXCEPTION,"the system \"%s\" is not authorized");
        en.put(FILE_REMOVE_EXCEPTION,"fail to remove file");
        en.put(FILE_STREAM_NOT_EXIST_EXCEPTION,"file stream is not exist");
        en.put(FILE_STREAM_EXPIRED_EXCEPTION,"file stream is expired");
        en.put(FILE_NOT_EXIST_EXCEPTION,"file is not exist");
        en.put(INVALID_REQUEST_EXCEPTION,"invalid request: %s");
        en.put(AUTHENTICATE_FAILURE_EXCEPTION,"authenticate failure: %s");
        en.put(AUTHORIZED_CODE_EXPIRED_EXCEPTION,"system code \"%s\" is expired");
    }

    private static ErrorMessage errorMessage = new ErrorMessage(zh, en);
}
